<html>
<head>
<title>iconActivity.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.s0 { color: #000080; font-weight: bold;}
.s1 { color: #000000;}
.s2 { color: #0000ff;}
</style>
</head>
<body bgcolor="#ffffff">
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#c0c0c0" >
<tr><td><center>
<font face="Arial, Helvetica" color="#000000">
iconActivity.java</font>
</center></td></tr></table>
<pre><span class="s0">package </span>com.example.myapplication2;

<span class="s0">import </span>androidx.appcompat.app.AppCompatActivity;

<span class="s0">import </span>android.graphics.drawable.Drawable;
<span class="s0">import </span>android.os.Bundle;
<span class="s0">import </span>android.view.View;
<span class="s0">import </span>android.widget.Button;

<span class="s0">public class </span>iconActivity <span class="s0">extends </span>AppCompatActivity <span class="s0">implements </span>View.OnClickListener{


    <span class="s0">private </span>Button btn_icon;
    <span class="s0">private </span>Drawable drawable;


    <span class="s0">protected void </span>onCreate(Bundle savedInstanceState) {
        <span class="s0">super</span>.onCreate(savedInstanceState);
        setContentView(R.layout.activity_icon);

        btn_icon = findViewById(R.id.btn_icon );
        drawable = getResources().getDrawable(R.mipmap.ic_launcher);
        drawable.setBounds(<span class="s2">0</span>,<span class="s2">0</span>,drawable.getMinimumWidth(),drawable.getMinimumHeight());

        findViewById(R.id.btn_left).setOnClickListener((View.OnClickListener) <span class="s0">this</span>);
        findViewById(R.id.btn_top).setOnClickListener((View.OnClickListener) <span class="s0">this</span>);
        findViewById(R.id.btn_right).setOnClickListener((View.OnClickListener) <span class="s0">this</span>);
        findViewById(R.id.btn_bottom).setOnClickListener((View.OnClickListener) <span class="s0">this</span>);



    }

    <span class="s0">public void </span>onClick(View v){
        <span class="s0">if</span>(v.getId() == R.id.btn_left){
            btn_icon.setCompoundDrawables(drawable,<span class="s0">null</span>,<span class="s0">null</span>,<span class="s0">null</span>);
        } <span class="s0">else if </span>(v.getId() == R.id.btn_top){
            btn_icon.setCompoundDrawables(<span class="s0">null</span>,drawable,<span class="s0">null</span>,<span class="s0">null</span>);
        } <span class="s0">else if </span>(v.getId() == R.id.btn_right){
            btn_icon.setCompoundDrawables(<span class="s0">null</span>,<span class="s0">null</span>,drawable,<span class="s0">null</span>);
        } <span class="s0">else if</span>(v.getId() == R.id.btn_bottom){
            btn_icon.setCompoundDrawables(<span class="s0">null</span>,<span class="s0">null</span>,<span class="s0">null</span>,drawable);
        }
    }
}</pre>
</body>
</html>